package com.wmh.baseservice.operationaid.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wmh.baseservice.common.mybatisplus.structure.LambdaQueryWrapperX;
import com.wmh.baseservice.common.utils.returnbody.ReturnBody;
import com.wmh.baseservice.operationaid.entity.KeyWordBrandCharacter;
import com.wmh.baseservice.operationaid.service.KeyWordBrandCharacterService;
import com.wmh.baseservice.operationaid.mapper.KeyWordBrandCharacterMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author dongaolong
 * @description 针对表【operation_aid_key_word_brand_character】的数据库操作Service实现
 * @createDate 2023-07-06 09:38:00
 */
@Service
public class KeyWordBrandCharacterServiceImpl extends ServiceImpl<KeyWordBrandCharacterMapper, KeyWordBrandCharacter>
        implements KeyWordBrandCharacterService {

    @Resource
    private KeyWordBrandCharacterMapper keyWordBrandCharacterMapper;

    @Override
    public String commitBrandCharacter(String name) {
        LambdaQueryWrapperX<KeyWordBrandCharacter> queryWrapper = new LambdaQueryWrapperX<KeyWordBrandCharacter>()
                .eq(KeyWordBrandCharacter::getName, name);

        KeyWordBrandCharacter entity = baseMapper.selectOne(queryWrapper);

        if (entity != null) {
             throw new RuntimeException("数据存在,无法插入新数据");
        } else {
            entity = new KeyWordBrandCharacter();
            entity.setName(name);
            saveOrUpdate(entity);
            return ReturnBody.success();
        }
    }

    @Override
    public void delete(List<Long> ids) {
        remove(new LambdaQueryWrapperX<KeyWordBrandCharacter>()
                .in(KeyWordBrandCharacter::getId, ids));
    }
}




